import 'dart:ui';

import 'package:flutter/material.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  final containerKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    final dpSize = MediaQuery.of(context).size;
    final pixelSize = window.physicalSize;
    final dpWidth = dpSize.width.ceilToDouble();
    final dpHeight = dpSize.height.ceilToDouble();
    final pxWidth = pixelSize.width;
    final pxHeight = pixelSize.height;

    return Scaffold(
      appBar: AppBar(
        title: Text(
            '''屏幕宽高(px) : $pxWidth x $pxHeight\n屏幕宽高(dp) : $dpWidth x $dpHeight'''),
      ),
      body: Container(
        key: containerKey,
        color: Colors.tealAccent,
        width: dpSize.width / 2,
        height: dpSize.height / 2,
        child: Text('${containerKey.currentContext}'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          print(containerKey.currentContext);
        },
      ),
    );
  }
}
